//
//  SSMineHeaderView.m
//  starspaceVR
//
//  Created by 曹端芹 on 17/10/9.
//  Copyright © 2017年 starspace. All rights reserved.
//

#import "SSMineHeaderView.h"
#import "SSUserInfoManager.h"
#import "SSUserInfoModel.h"
#import "UIButton+SSImagePosition.h"

#define pictureURL @"http://www.vrspaces.cn"

@interface SSMineHeaderView ()

@property (nonatomic,strong) UIImageView *avatorImgView;
@property (nonatomic,strong) UILabel *nickNameL;
@property (nonatomic,strong) UILabel *userNameL;
@property (nonatomic,strong) UILabel *pointsL;
@property (nonatomic,strong) UILabel *balanceL;

@end

@implementation SSMineHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void) setupUI {
    
    UIView *backView = [[UIView alloc] init];
    backView.frame = CGRectMake(0, 0, self.frame.size.width, 100);
    backView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.9f];
    [self addSubview:backView];
    
    UIView *buttonView = [[UIView alloc] init];
    buttonView.frame = CGRectMake(0, 100, self.frame.size.width, 60);
    buttonView.backgroundColor = [UIColor whiteColor];
    [self addSubview:buttonView];
    
    
    self.avatorImgView = [[UIImageView alloc] init];
    self.avatorImgView.frame = CGRectMake(15, 10, 80, 80);
    self.avatorImgView.layer.cornerRadius = 40;
    self.avatorImgView.clipsToBounds = YES;
    [self addSubview:self.avatorImgView];
    
   
    
    self.nickNameL = [[UILabel alloc] init];
    
    self.nickNameL.textColor = [UIColor whiteColor];
    self.nickNameL.font = kFont(12);
    [self addSubview:self.nickNameL];
    [self.nickNameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(20);
        make.left.mas_equalTo(self.avatorImgView.mas_right).mas_offset(15);
        make.height.mas_equalTo(20);
        make.right.mas_offset(-10);
    }];
    
    self.userNameL = [[UILabel alloc] init];
   
    self.userNameL.textColor = [UIColor whiteColor];
    self.userNameL.font = kFont(12);
    [self addSubview:self.userNameL];
    [self.userNameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(self.nickNameL);
        make.top.mas_equalTo(self.nickNameL.mas_bottom);
    }];
    
    
    self.pointsL = [[UILabel alloc] init];
   
    self.pointsL.textColor = [UIColor whiteColor];
    self.pointsL.font = kFont(12);
    [self addSubview:self.pointsL];
    [self.pointsL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(self.nickNameL);
        make.top.mas_equalTo(self.userNameL.mas_bottom);
    }];

    
    CGFloat btnW = self.frame.size.width / 4;
    CGFloat btnH = 60;
    
    NSArray *titleArray = @[@"账户余额",@"收藏管理",@"站内信息",@"积分详情"];
    NSArray *imageNameArray = @[@"mine_balance",@"mine_collection",@"mine_message",@"mine_points"];
    for (int i = 0; i < titleArray.count; i ++ ) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(i * btnW, 0, btnW, btnH);
        button.titleLabel.font = kFont(12);
        [button setTitleColor:kRGBColor(113, 113, 113) forState:UIControlStateNormal];
        [button setTitle:titleArray[i] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:imageNameArray[i]] forState:UIControlStateNormal];
        [button setImagePosition:SSImagePositionTop spacing:5];
        [buttonView addSubview:button];
    }
    
}


- (void)setUserInfo:(SSUserInfoModel *)userInfo {
    _userInfo = userInfo;
     [self.avatorImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",pictureURL,userInfo.avatar]] placeholderImage:[UIImage imageNamed:placeholderImageName]];

    self.nickNameL.text = [NSString stringWithFormat:@"尊敬的会员:%@",userInfo.nickName];
     self.userNameL.text = [NSString stringWithFormat:@"登录账号:%@",userInfo.loginName];
     self.pointsL.text = [NSString stringWithFormat:@"积分:    %@",userInfo.point];
}



@end
